<template>
  <div class="login-box">
    <div class="login-logo">
      <a href="../../index2.html"><b>UMS</b> 3.0</a>
    </div>
    <!-- /.login-logo -->
    <div class="login-box-body">
      <p class="login-box-msg"></p>

      <form @submit.prevent="doLogin">
        <div class="form-group has-feedback">
          <input type="email" class="form-control" placeholder="邮箱" v-model="user.email">
          <span class="glyphicon glyphicon-envelope form-control-feedback"></span>
        </div>
        <div class="form-group has-feedback">
          <input type="password" class="form-control" placeholder="密码" v-model="user.password">
          <span class="glyphicon glyphicon-lock form-control-feedback"></span>
        </div>
        <div class="row">
          <div class="col-xs-8">
            <div class="checkbox">
              <label>
                <input type="checkbox"> 保持登陆
              </label>
            </div>
          </div>
          <!-- /.col -->
          <div class="col-xs-4">
            <button type="submit" class="btn btn-primary btn-block btn-flat">登陆</button>
          </div>
          <!-- /.col -->
        </div>
      </form>

      <div class="social-auth-links text-center">
        <p>- 其它方式登陆 -</p>
        <a href="#" class="btn btn-block btn-social btn-facebook btn-flat"><i class="fa fa-qq"></i> QQ </a>
        <a href="#" class="btn btn-block btn-social btn-google btn-flat"><i class="fa fa-wechat"></i> 微信 </a>
      </div>
      <!-- /.social-auth-links -->

      <a href="#">忘记密码</a> / 
      <a href="register.html" class="text-center">注册</a>

    </div>
    <!-- /.login-box-body -->
  </div>
</template>

<script>
import * as API from "../Consts/Api";

export default {
  data() {
    return {
      user: {
        email: "",
        password: ""
      }
    };
  },

  methods: {
    doLogin() {
      this.$http.post(API.LOGIN, this.user).then(response => {
        if (response.data.status == "no") {
          this.$message({
            message: response.data.message,
            type: "error",
            duration: 5000
          });
        } else {
          let user = response.data.data;
          // 保存token，并跳转
          this.$storage.set("user", user);
          this.$router.push("/dashboard");
        }
      });
    }
  }
};
</script>
